package com.eos.control.action.customer;

import com.eos.business.service.SysCustomerBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.DataCacheUtil;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysCustomer;
import com.eos.orm.mybatis.model.SysUser;
import com.hf.utils.StringUtil;

public class SaveCustomerAction extends AbstractBaseAction {
	private static final long serialVersionUID = 4086419020328217905L;
	private String customerName;
	private String nickName;
	private String legalPerson;
	private String linkAddr;
	private String postCode;
	private String customerType;
	private String sysUser;
	private String customerDesc;
	private String customerCode;

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public void setLegalPerson(String legalPerson) {
		this.legalPerson = legalPerson;
	}

	public void setLinkAddr(String linkAddr) {
		this.linkAddr = linkAddr;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public void setCustomerType(String customerType) {
		this.customerType = customerType;
	}

	public void setSysUser(String sysUser) {
		this.sysUser = sysUser;
	}

	public void setCustomerDesc(String customerDesc) {
		this.customerDesc = customerDesc;
	}

	public void setCustomerCode(String customerCode) {
		this.customerCode = customerCode;
	}

	@Override
	public String execute() {
		try {
			SysUser loginUser = (SysUser) getSession().getAttribute("SysUser");
			String loginUserId = loginUser.getId() + "";
			SysCustomer customer = new SysCustomer();
			customer.setCustomerAddress(linkAddr);
			customer.setCustomerDesc(customerDesc);
			customer.setCustomerName(customerName);
			customer.setCustomerPostcode(postCode);
			customer.setCustomerShort(nickName);
			customer.setCustomerType(customerType);
			customer.setDealFlag(ConstantTool.DEAL_FALG_OK);
			String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
			customer.setInsertTime(strTime);
			customer.setInsertUserId(loginUserId);
			customer.setLegalPerson(legalPerson);
			customer.setModifyTime(strTime);
			customer.setStatus(ConstantTool.STATUS_OK);
			if(StringUtil.isEmpty(sysUser) || "0".equals(sysUser))
				sysUser = loginUserId;
			customer.setSysUserId(sysUser);
			customer.setCustomerCode(customerCode);
			customer.setUpdateUserId(loginUserId);
			SysCustomerBusinessService scbs = new SysCustomerBusinessService();
			String exeStatus = scbs.saveCustomer(customer);
			if("SUCCESS".equals(exeStatus)){
				statusCode = "200";
				message = "新增客户信息成功!";
				DataCacheUtil.clearSysCustomerMap();
			}else{
				statusCode = "300";
				message = "系统繁忙, 新增客户信息失败!";
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			statusCode = "300";
			message = "系统异常, 新增供应商失败!";
		}
		return SUCCESS;
	}
}
